<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui"/>
  <meta name="apple-mobile-web-app-capable" content="yes"/>
  <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
  <meta name="format-detection" content="telephone=no, email=no"/>
  <meta charset="UTF-8">
  <title>购物车</title>
  <link rel="stylesheet" href="${request.contextPath}/static/front/themes/css/core.css">
  <link rel="stylesheet" href="${request.contextPath}/static/front/themes/css/icon.css">
  <link rel="stylesheet" href="${request.contextPath}/static/front/themes/css/home.css">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link href="iTunesArtwork@2x.png" sizes="114x114" rel="apple-touch-icon-precomposed">
</head>
<body>

<header class="aui-header-default aui-header-fixed ">
  <a href="javascript:history.back(-1)" class="aui-header-item">
    <i class="aui-icon aui-icon-back"></i>
  </a>
  <div class="aui-header-center aui-header-center-clear">
    <div class="aui-header-center-logo">
      <div class="">购物车(<span id="carVoNum">${carVoNum!'0'}</span>)</div>
    </div>
  </div>
  <a href="#" class="aui-header-item-icon"   style="min-width:0">
    <i class="aui-icon aui-icon-member"></i>
  </a>
</header>
<section class="aui-car-content">
  <div class="aui-dri"></div>
  <div class="aui-car-box">
    <div class="aui-car-box-name">
      <input type="checkbox" class="check goods-check all-check">
      <h3>
        <a href="#">我的商品</a>
      </h3>
      <div class="aui-car-coupons">
        <a href="#">领券</a>
        <a href="javascript:void(0);" id="deleteCar">删除</a>
      </div>
    </div>
    <div class="aui-car-box-list">
      <ul>
      <#list carVoList as carVo>
        <li class="parent-li">
          <div class="aui-car-box-list-item shop-info">
            <input type="hidden" class="prod-id" id="prodId${carVo.prodId}" value="${carVo.prodId}">
            <input type="checkbox" class="check goods-check sigle-check">
            <div class="aui-car-box-list-img">
              <a href="ui-product.html">
                <img src="${request.contextPath}${carVo.prodImg}" alt="">
              </a>
            </div>
            <div class="aui-car-box-list-text">
              <h4>
                <a href="ui-product.html">${carVo.prodName}/${carVo.prodUnit}&nbsp;&nbsp;【质量在的心中，名牌在的手中，责任在的肩上，诚信在的言行中】</a>
              </h4>
              <div class="aui-car-box-list-text-brief">
                <span>重量:3.3kg</span>
                <span>颜色:标配版</span>
                <span>版本:5.7英寸</span>
              </div>
              <div class="aui-car-box-list-text-price">
                <div class="aui-car-box-list-text-pri">
                  ￥<b class="price">${carVo.disPrice}</b>
                </div>
                <div class="aui-car-box-list-text-arithmetic">
                  <a href="javascript:;" class="minus">-</a>
                  <span class="num">${carVo.prodNum}</span>
                  <a href="javascript:;" class="plus">+</a>
                </div>
              </div>
            </div>
          </div>
          <div class="aui-dri"></div>
        </li>
      </#list>
      </ul>
    </div>
    <#--<div class="aui-shopPrice">
      本店总计：￥
      <span class="aui-total-amount ShopTotal">3990.00</span>
    </div>-->
  </div>
</section>
<div class="aui-payment-bar">
  <div class="all-checkbox"><input type="checkbox" class="check goods-check all-check" id="AllCheck">全选</div>
  <div class="shop-total">
    <strong>合计：<i class="total" id="AllTotal">0.00</i></strong>
  </div>
  <a href="order.html" class="settlement">去结算</a>
</div>
<script src="${request.contextPath}/static/front/themes/js/jquery.min.js"></script>
<script src="${request.contextPath}/static/common/common.js?v=${staticVersion}"></script>
<script type="text/javascript">
  function getContextPath(){
    return "${request.contextPath}";
  }

 $(function () {
   // 数量减
   $(".minus").click(function() {
     var t = $(this).parent().find('.num');
     t.text(parseInt(t.text()) - 1);
     if (t.text() <= 1) {
       t.text(1);
     }
     var that = $(this);
     addCar(that);
     totalPrice()
   });
   // 数量加
   $(".plus").click(function() {
     var t = $(this).parent().find('.num');
     t.text(parseInt(t.text()) + 1);
     if (t.text() <= 1) {
       t.text(1);
     }
     var that = $(this);
     addCar(that);
     totalPrice()
   });

   $(".sigle-check").click(function () {
     totalPrice();
   });

   $(".all-check").click(function () {
     if ($(this).prop("checked") == true) { //如果全选按钮被选中
       $(".sigle-check").each(function () {
         if (!$(this).is(":checked")) {
           $(this).prop('checked', true);
         }
       })
       $(".all-check").each(function () {
         $(this).prop('checked', true);
       })
     }else{
       $(".sigle-check").each(function () {
         if ($(this).is(":checked")) {
           $(this).prop('checked', false);
         }
       })
       $(".all-check").each(function () {
         $(this).prop('checked', false);
       })
     }
     totalPrice();
   });
   
   $("#deleteCar").click(function () {
     var checkNum = 0;
     $(".sigle-check").each(function() {
       if ($(this).is(":checked")) { //如果该商品被选中
         checkNum = checkNum + 1;
       }
     });
     if(checkNum==0){
       alert("请先勾选商品");
       return false;
     }
     if(confirm("确定删除商品吗？")){
       var deleteIds = [];
       var i = 0;
       $(".sigle-check").each(function() {
         if ($(this).is(":checked")) { //如果该商品被选中
           var prodId = $(this).parents(".shop-info").find(".prod-id").val();
           deleteIds[i] = prodId;
           i++;
         }
       });
       var data = {'deleteIds':deleteIds};
       var url = '${request.contextPath}/car/deleteCar';
       var result = ajaxPost(url,data);
       if(null != result && null != result.success && result.success){
         var carVoNum = $("#carVoNum").text();
          for(var i = 0; i<deleteIds.length; i++){
             $("#prodId"+deleteIds[i]).parents(".parent-li").remove();
            carVoNum = parseInt(carVoNum) - 1;
          }
          $("#carVoNum").text(carVoNum)
         totalPrice();
       }
     }
   });
   
 })


 function totalPrice() {
    var allprice = 0; //总价
    $(".sigle-check").each(function() {
     if ($(this).is(":checked")) { //如果该商品被选中
       var num = parseInt($(this).parents(".shop-info").find(".num").text()); //得到商品的数量
       var price = parseFloat($(this).parents(".shop-info").find(".price").text()); //得到商品的单价
       var total = price * num; //计算单个商品的总价
       allprice += total; //计算所有店铺的总价
     }
   });
   $("#AllTotal").text(allprice.toFixed(2)); //输出全部总价
 }


 function addCar(that) {
   var num = that.parent().find(".num").text();
   var prodId = that.parents(".shop-info").find(".prod-id").val();
   addToCar(prodId,parseInt(num),false);
 }
</script>
</body>
</html>